import { _decorator, Camera, Component, Node, Quat, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('CameraCtrl')
export class CameraCtrl extends Component {

    @property({ type: Camera })
    public Camera: Camera = null;

    protected onLoad(): void {
        if (!Camera) {
            this.Camera = this.node.getComponent(Camera);
        }
    }

    start() {

    }

    update(deltaTime: number) {
  
    }

    public TweenTo(node: Node, duration: number,onOver: ()=> void) {
        let quat: Quat = new Quat();
        Quat.fromEuler(quat, node.eulerAngles.x, node.eulerAngles.y, node.eulerAngles.z);
        tween(this.node)
            .to(duration, {
                position: node.position,
                rotation: quat
            },
            {
                onComplete : onOver
            }).start();
    }
}


